package com.atguigu.springcloud.service.impl;

import com.atguigu.springcloud.service.IMessageProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author xiangdd
 * @since 2021/12/20
 */


@EnableBinding(Source.class)
public class MessageProviderImpl implements IMessageProvider {



    @Output(Source.OUTPUT)
    @Resource
    private MessageChannel messageChannel;


    @Override
    public void send() {
        String serial = UUID.randomUUID().toString();
        messageChannel.send(MessageBuilder.withPayload(serial).build());
        System.out.println("************serial:" + serial);
    }
}
